@extends('backend/layouts/default')
@section('title')
Tạo thành viên mới ::
@parent
@stop
@section('content')
<h3>
    <span class="glyphicon glyphicon-user"></span> Tạo người dùng mới
</h3>
<form class="form-horizontal" role="form" method="post" action="" autocomplete="off">
    {{Form::token()}}
    <div class="box box-solid">
        <div class="box-header"></div>
        <div class="box-body">
            <div class="row">
                <div class="col-md-4 col-sm-5">
                    <h4>Thông tin cơ bản</h4>

                    <div>
                        <div class="form-group {{$errors->has('username') ? 'error': ''}}">
                            <label class="control-label col-sm-4" for="username">Tên đăng nhập:</label>

                            <div class="col-sm-8">
                                <?= Form::text('data[User][username]', Input::old('data[User][username]'), array('id' => 'data[User][username]', 'class' => 'form-control')) ?>
                                <?= $errors->first('username', '<span class="help-inline">:message</span>') ?>
                            </div>
                        </div>
                        <div class="form-group {{$errors->has('email') ? 'error': ''}}">
                            <label class="control-label col-sm-4" for="email">Email:</label>

                            <div class="col-sm-8">
                                {{Form::text('data[User][email]',Input::old('data[User][email]'),
                                array('id'=>'data[User][email]', 'class'=>'form-control'))}}
                                {{ $errors->first('email', '<span class="help-inline">:message</span>') }}
                            </div>
                        </div>
                        <div class="form-group {{$errors->has('email') ? 'error': ''}}">
                            <label class="control-label col-sm-4" for="email">Mật khẩu:</label>

                            <div class="col-sm-8">
                                <?= Form::password('data[User][password]', array('id' => 'data[User][password]', 'class' => 'form-control')) ?>
                                <?= $errors->first('password', '<span class="help-inline">:message</span>') ?>
                            </div>
                        </div>
                        <div class="form-group {{$errors->has('email') ? 'error': ''}}">
                            <label class="control-label col-sm-4" for="email">Xác nhận mật khẩu:</label>

                            <div class="col-sm-8">
                                <?= Form::password('data[User][confirm_password]', array('id' => 'data[User][confirm_password]', 'class' => 'form-control')) ?>
                                <?= $errors->first('confirm_password', '<span class="help-inline">:message</span>') ?>
                            </div>
                        </div>
                        <div class="form-group {{ $errors->has('activated') ? 'error' : '' }}">
                            <label class="control-label col-md-4" for="activated">Kích hoạt:</label>

                            <div class="col-md-8">
                                <select class="form-control" name="activated" id="activated">
                                    <option value="1">@lang('general.yes')</option>
                                    <option value="0">@lang('general.no')</option>
                                </select>
                                {{ $errors->first('activated', '<span class="help-inline">:message</span>') }}
                            </div>
                        </div>
                        <div class="form-group {{ $errors->has('groups') ? 'error' : '' }}">
                            <label class="control-label col-md-4" for="groups">Nhóm</label>

                            <div class="col-md-8">
                                <select class="form-control" name="data[Groups]" id="data[Groups]" multiple>
                                    @foreach ($data['Groups'] as $group)
                                    <option value="{{ $group->id }}">{{ $group->name }}</option>
                                    @endforeach
                                </select>

                                <span class="help-block">
                                    Chọn nhóm để gán quyền cho người dùng, mỗi người dùng chỉ có quyền hạn trên các nhóm mà họ được gán quyền.
                                </span>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="col-md-8 col-sm-7">
                    <h4>Quyền hạn</h4>

                    <div>
                        @foreach ($data['Permissions'] as $area => $permissions)
                        <table class="table table-bordered">
                            <tr>
                                <th>{{ $area }}</th>
                                <th style="width: 40px"><span class="label label-success">Cho phép</span></th>
                                <th style="width: 40px"><span class="label label-danger">Từ chối</span></th>
                                <th style="width: 40px"><span class="label label-warning">Kế thừa</span></th>
                            </tr>
                            @foreach ($permissions as $permission)
                            <tr>
                                <td>{{ $permission['label'] }}</td>
                                <td>
                                    <input type="radio" value="1" id="{{ $permission['permission'] }}_allow"
                                           name="permissions[{{ $permission['permission'] }}]"{{
                                    (array_get($data['selectedPermissions'], $permission['permission']) === 1 ? '
                                    checked="checked"' : '') }}>
                                </td>
                                <td>
                                    <input type="radio" value="-1" id="{{ $permission['permission'] }}_deny"
                                           name="permissions[{{ $permission['permission'] }}]"{{
                                    (array_get($data['selectedPermissions'], $permission['permission']) === -1 ? '
                                    checked="checked"' : '') }}>
                                </td>
                                <td>
                                    @if ($permission['can_inherit'])<input type="radio" value="0"
                                                                           id="{{ $permission['permission'] }}_inherit"
                                                                           name="permissions[{{ $permission['permission'] }}]"{{
                                    ( ! array_get($data['selectedPermissions'], $permission['permission']) ? '
                                    checked="checked"' : '') }}>@endif
                                </td>
                            </tr>
                            @endforeach
                        </table>
                        @endforeach
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="control-group" align="right">
        <div class="controls">
            <a class="btn btn-link" href="{{ route('users') }}">Hủy</a>
            <button type="submit" class="btn btn-success">Tạo mới</button>
        </div>
    </div>
</form>
@stop
